package examples.books

import de.saxsys.mvvmfx.ViewModel
import de.saxsys.mvvmfx.utils.mapping.ModelWrapper
import de.saxsys.mvvmfx.utils.mapping.accessorfunctions.StringGetter
import de.saxsys.mvvmfx.utils.mapping.accessorfunctions.StringSetter
import examples.books.backend.Book
import groovy.transform.CompileStatic
import javafx.beans.property.ReadOnlyStringProperty
import javafx.beans.property.ReadOnlyStringWrapper
import javafx.beans.property.StringProperty


/**
 * Created by Misty on 2015/6/4.
 */
@CompileStatic
class BookListItemViewModel implements ViewModel {
    private ReadOnlyStringWrapper title = new ReadOnlyStringWrapper()
    private ReadOnlyStringWrapper author = new ReadOnlyStringWrapper()

    final Book book

    public BookListItemViewModel(Book book) {
        this.book = book
        reload()
    }

    void reload() {
        title.set(book.title)
        author.set("(${book.author})")
    }

    void reset() {
        title.set("")
        author.set("")
    }

    ReadOnlyStringProperty getTitle() {
        return title.readOnlyProperty
    }

    ReadOnlyStringProperty getAuthor() {
        return author.readOnlyProperty
    }
}
